package com.example.cinema.request;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.cinema.bindingdata.CarouseData;
import com.example.cinema.database.AppDataBase;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class BlanFragmentRequest {
    private String url;
    private Context context;
    public BlanFragmentRequest(Context context) {
        this.context = context;
        try {
            ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            url = info.metaData.getString("url");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
    //获取轮播数据
    public List<CarouseData> GetLunBo()
    {
        List<CarouseData> data = new ArrayList<>();
        AppDataBase dataBase = new AppDataBase(context.getApplicationContext(),"poster",null,2);
        SQLiteDatabase database = dataBase.getWritableDatabase();
        Cursor cursor = database.rawQuery("SELECT * FROM poster",null);
        if(cursor.getCount()>0)
        {
            cursor.moveToFirst();
            while (!cursor.isAfterLast())
            {
                CarouseData cdata = new CarouseData();
                cdata.address = cursor.getString(cursor.getColumnIndex("urls"));
                Log.i("UUUU",cdata.address);
                cdata.news = cursor.getString(cursor.getColumnIndex("news"));
                cdata.imgurl = cursor.getString(cursor.getColumnIndex("image"));
                Log.i("UUUU",cdata.imgurl);
                cdata.type = cursor.getInt(cursor.getColumnIndex("types"));
                Log.i("UUUU",cdata.type+"");
                data.add(cdata);
                cursor.moveToNext();
                Log.i("UUU","执行文笔");
            }
            cursor.close();
        }
        return data;
    }

}
